public class Test3_2 {
    public static int getDuplicate(int[] number){
        if (number == null || number.length  < 1) return -1;
        for (int i : number){
            if ( i < 0 || i > number.length-1) return  -1;//判断输入的数字是否在范围内
        }
        int start = 1;
        int end = number.length-1;
        while (end >= start){
            int mid = (end-start)/2+start;
            int count = countRange(number,start,mid); //每一段在数组中重复出现的次数
            if (end == start){
                if (count > 1) return start;
                else break;
            }
            if (count > (mid-start+1)) end = mid;
            else start = mid+1;
        }
        return -1;
    }
    public static int countRange(int[] number,int start,int end){
        int count = 0;
        for (int i = 0;i < number.length;i++){
            if (number[i] >= start && number[i] <= end) count ++;
        }
        return count;
    }

    public static void main(String[] args) {
        int[] numbers2 = {2,3,5,4,3,2,6,7};
        System.out.println(getDuplicate(numbers2));
    }
}
